#include <asm/sbidef.h>
#include <asm/sbiasm.h>

// #define BOOT_LOADER_SIG_OFFSET 0x1fe
// #define OS_SIZE_LOC (BOOT_LOADER_SIG_OFFSET - 2)
// #define OS_SIZE_LOC 0x1fc

.equ os_size_loc, 0x502001fc

// 1. kernel address (move kernel to here ~)
.equ kernel, 0x50201000//涓嶉噰鐢ㄩ噸瀹氫綅

// 2. kernel main address (jmp here to start kernel main!)
.equ kernel_main, 0x50201000

.text
.global main

main:
	// fence on all memory and I/O
	fence

	// print a \n to avoid system output error...
	li a0, 10
	SBI_CALL SBI_CONSOLE_PUTCHAR

	// 1) task1 call BIOS print string "It's bootblock!"
	la a0, msg
	SBI_CALL SBI_CONSOLE_PUTSTR

	// 2) task2 call BIOS read kernel in SD card and jump to kernel start
	la t1, os_size_loc//get an adress that stroing the length of kernel which is computed in creatimage
	lh t1, 0(t1)//make t1 into a number
	//涓轰簡鍋欳-score锛屽緱鎶奲ootblock缁欑Щ璧?杩欓噷浠巗d鍗￠噸鏂拌涓€浠絙ootblock
	//la a0, 0x50200000
	//slli t2, t1, 10//t2 is 瀛楄妭
	//add a0, t2, a0 
	//li a1, 1
	//li a2, 0
	//SBI_CALL SBI_SD_READ
	//add t0, a0, zero
	//addi t0, t0, 74
	//jr t0 //棰濆娣诲姞鐨凜-score閮ㄥ垎缁撴潫
	la a0, kernel
	add a1, zero, t1
	addi a2, zero, 1
	SBI_CALL SBI_SD_READ
	la t0, kernel
	jr t0
// while(1) --> stop here
stop:
	j stop
	nop

.data

msg: .string "It's a bootloader...\n\r"


